package cn.wolfcode.luowowo.website.util;

import cn.wolfcode.luowowo.cache.keys.RedisKeys;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class CookieUtil {
    public static String getToken(HttpServletRequest req, HttpServletResponse resp){
        Cookie[] cookies = req.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if ("TOKEN".equals(cookie.getName())) {
                    cookie.setMaxAge(RedisKeys.USER_LOGIN_TOKEN.getTime().intValue());
                    cookie.setPath("/");
                    resp.addCookie(cookie);
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
